package day16;

import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            String[] str2 = str.split("-");
            String[] a1 = str2[0].split(" ");
            String[] a2 = str2[1].split(" ");
            String a = "34567891JQKA2";
            if(str2[0].equals("joker JOKER") || str2[1].equals("joker JOKER")) {
                System.out.println("joker JOKER");
            }else if(a1.length == a2.length) {
                //个子，对子，三子比较
                if(a.indexOf(a1[0].substring(0,1)) > a.indexOf(a2[0].substring(0,1))) {
                    System.out.println(str2[0]);
                }else {
                    System.out.println(str2[1]);
                }


            }else if(a1.length == 4){
                System.out.println(str2[0]);
            } else if(a2.length == 4) {
                System.out.println(str2[1]);
            } else {
                System.out.println("ERROR");
            }
        }
    }
}
